package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	GoodsName   string  `gorm:"type:varchar(30);"`
	GoodsCover  string  `gorm:"type:varchar(255)"`
	GoodsPrice  float64 `gorm:"type:decimal(10,2)"`
	GoodsStock  int64   `gorm:"type:int(10)"`
	GoodsStatus string  `gorm:"goodsStatus"`
}

func (g *Goods) Create() error {
	return DB.Debug().Create(&Goods{}).Error
}
func (g *Goods) UpdateStatus(goodsId, status int64) error {
	return DB.Debug().Model(&Goods{}).Where("id=?", goodsId).Update("goods_status", status).Error
}
func (g *Goods) GoodsList(status int64) (list []*Goods, err error) {
	if status == 0 {
		DB.Debug().Find(&list)
	} else {
		DB.Debug().Where("goods_status=?", status).Find(&list)
	}
	return
}
